module Singly
  class Profiles
    include Singly::Endpoint

    endpoint :get, "/profiles", required: [:access_token], optional: [:data, :verify]

    # Delete all the things!
    def delete
      Singly::Profiles::Delete.new(creds)
    end

    # CUSTOM PROFILE MANAGEMENT

    # If params is nil, or only contains
    # required parameters, it sends a GET.
    # Otherwise it sends a POST.
    def self(params=nil)
      params ||= {}
      if (params.keys - self.class.required_params).empty?
        Singly::Profiles::Self.new(creds)
      else
        Singly::Profiles::SelfUpdate.new(creds.merge(params))
      end
    end

    # SUPPORTED SERVICES SECTION

    def thirtysevensignals(params={})
      service("37signals", params)
    end

    def bodymedia(params={})
      service(__method__, params)
    end

    def dropbox(params={})
      service(__method__, params)
    end

    def dwolla(params={})
      service(__method__, params)
    end

    def facebook(params={})
      service(__method__, params)
    end

    def fitbit(params={})
      service(__method__, params)
    end

    def flickr(params={})
      service(__method__, params)
    end

    def foursquare(params={})
      service(__method__, params)
    end

    def gcal(params={})
      service(__method__, params)
    end

    def gcontacts(params={})
      service(__method__, params)
    end

    def gdocs(params={})
      service(__method__, params)
    end

    def github(params={})
      service(__method__, params)
    end

    def gmail(params={})
      service(__method__, params)
    end

    def google(params={})
      service(__method__, params)
    end

    def gplus(params={})
      service(__method__, params)
    end

    def imgur(params={})
      service(__method__, params)
    end

    def instagram(params={})
      service(__method__, params)
    end

    def klout(params={})
      service(__method__, params)
    end

    def linkedin(params={})
      service(__method__, params)
    end

    def meetup(params={})
      service(__method__, params)
    end

    def paypal(params={})
      service(__method__, params)
    end

    def picasa(params={})
      service(__method__, params)
    end

    def rdio(params={})
      service(__method__, params)
    end

    def reddit(params={})
      service(__method__, params)
    end

    def runkeeper(params={})
      service(__method__, params)
    end

    def shutterfly(params={})
      service(__method__, params)
    end

    def soundcloud(params={})
      service(__method__, params)
    end

    def stocktwits(params={})
      service(__method__, params)
    end

    def tout(params={})
      service(__method__, params)
    end

    def tumblr(params={})
      service(__method__, params)
    end

    def twitter(params={})
      service(__method__, params)
    end

    def withings(params={})
      service(__method__, params)
    end

    def wordpress(params={})
      service(__method__, params)
    end

    def yammer(params={})
      service(__method__, params)
    end

    def youtube(params={})
      service(__method__, params)
    end

    def zeo(params={})
      service(__method__, params)
    end

    private

    def service(service, params)
      params ||= {}
      endpoint = Singly::Profiles::Service.new(creds.merge(params.merge(service: service.to_s)))
      endpoint.service = service.to_s
      endpoint
    end
  end
end